package model.utils;

import javax.vecmath.Tuple3d;

public class Algebra {

    public static double modv(Tuple3d v) {
        return Math.sqrt( Math.pow(v.x,2) + Math.pow(v.y, 2) + Math.pow(v.z, 2));
    }

    public static void normalize(Tuple3d v){
        double modv = modv(v);
        double eps = 1.0E-10;

        if (Math.abs(modv) < eps)
            return;
        
        v.set(v.x/modv,v.y/modv,v.z/modv);
    }

    public static double dot3(Tuple3d p1, Tuple3d p2) {
        return (p1.x * p2.x + p1.y*p2.y + p1.z*p2.z);
    }
    
    public static double getCoord(double i1, double i2, double w1, double w2, double p)
	{
		double eps = 1.0E-5;
		if (Math.abs(i2 - i1) < eps) 
			return 0;
		return ((p - i1) / (i2 - i1)) * (w2 - w1) + w1;
	}


}
